const pubUrl = "http://www.kangliuyong.com:10002"
const appkey = 'U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA='

function showToast() {
  wx.showLoading({
    title: '加载中',
  })
}

function hideToast() {
  wx.hideLoading()
}

const http = (options) => {
  showToast()
  options.data = options.data ? options.data : {}
  options.data.appkey = appkey
  return new Promise((resolve, reject) => {
    wx.request({
      url: pubUrl + options.url,
      method: options.method || 'get',
      data: options.data,
      header: options.header || {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success(res) {
        hideToast()
        resolve(res)
      } ,
      fail(err) {
        hideToast()
        reject(err)
      } 
    })
  })
}
export default http
